package com.qk.controller;

import com.qk.commen.PageResult;
import com.qk.commen.Result;
import com.qk.entity.Dept;
import com.qk.mapper.DeptMapper;
import com.qk.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.naming.ldap.PagedResultsControl;

@RestController
public class DeptController {
    @Autowired
    private DeptService deptService;
    @Autowired
    private DeptMapper deptMapper;

    @PostMapping("/depts")
    public Result add(@RequestBody Dept dept ){
        System.out.println("新增部门"+ dept);
        deptService.add(dept);
        return Result.success();
    }
    @GetMapping("/depts")
    public Result list(String name, Integer status,
                       @RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10")Integer pageSize){
        System.out.println("列表查询"+ name+ "-"+ status);
        //调用service,分页查询
        PageResult<Dept> list =deptService.list(name,status,page,pageSize);
        return Result.success(list);

    }

    @GetMapping("/depts/{id}")
    public Result getById(@PathVariable Integer id){
        System.out.println("查询部门id"+ id);
        Dept dept = deptService.getById(id);
        return Result.success(dept);
    }

    @PutMapping("/depts")
    public Result Dpdate(@RequestBody Dept dept){
        System.out.println("修改部门"+ dept);
        deptService.update(dept);
        return Result.success();

    }

    @DeleteMapping("/depts/{id}")
    public Result deleteById(@PathVariable Integer id){
        System.out.println("删除部门id"+ id);
        deptService.deleteById(id);
        return Result.success();
    }



}
